// pages/my/my.js
var util = require('../../utils/util.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    NickName: '请登录',    
    header: '',
    myList: [
      {
      "myIcon": "../../image/mine_12.png",
      "myTitle": "未绑定手机号",
      "text":"",
      "url": "bound/bound"
    },
    {
      "myIcon": "../../image/mine_05.png",
      "myTitle": "修改密码",
      "url": "change/change"
    },
     {
      "myIcon": "../../image/mine_11.png",
      "myTitle": "我的收藏",
        "url":"store/store"
    }, {
      "myIcon": "../../image/mine_14.png",
      "myTitle": "客服帮助",
      "url": "service/service"
     },
      {
       "myIcon": "../../image/mine_07.png",
       "myTitle": "客服电话",
      //  "text": "123456",
       "url": "tel/tel"
     }, 
      { 
      "myIcon": "../../image/mine_04.png",
      "myTitle": "关于我们",
      "url": "about/about"
    }],
    myNum: [{
      "num": "50.00",
      "text": "消费红包"
    }, {
      "num": "52.00",
      "text": "分享红包"
    }]
  },
  // click:function(e){
  //   var $idx = e.currentTarget.dataset.idx;
  //   if($idx==4){
  //     var phoneNumber = this.data.myList[4].text
  //     wx.makePhoneCall({
  //       phoneNumber: phoneNumber, //此号码并非真实电话号码，仅用于测试  
  //       success: function () {
  //         console.log("拨打电话成功！")
  //       },
  //       fail: function () {
  //         console.log("拨打电话失败！")
  //       }
  //     })
  //   }else{
  //   }
  // },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    util.GetUserInfo("您点击了拒绝授权,将无法获取个人信息,点击确定重新获取授权。");
    this.GetUserInfo();    
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.GetUserInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.GetUserInfo();
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  GetUserInfo:function(){ //获取用户信息    
    var that = this;
    wx.getStorage({
      key: 'UserID',
      success: function (res) {
        var data = {
          id: res.data
        }
        data.act = "Find_UserByID";
        util.Ajax(data, function (json) {
          if(json.data.Mobile!=""){
            //that.setData({ myList[0].myTitle:"已绑定手机号："+json.Mobile})
            var title = "已绑定手机号" ;
            var text = json.data.Mobile
            that.setData({ "myList[0].myTitle": title,"myList[0].text":text, "myList[0].url":"" });            
          }          
        });   
        
      }
    }),
    wx.getStorage({
      key: 'NickName',
      success: function (res) {
        //console.log(res);
        that.setData({NickName:res.data});
      }
    }),
    wx.getStorage({
      key: 'HeadImg',
      success: function (res) {
        that.setData({ HeadImg: res.data });
      }
    })
  }  
})